<%--
  Created by IntelliJ IDEA.
<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2017/4/12
  Time: 10:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--解析表达式--%>
<%@ page isELIgnored="false" %>
<%--引入jstl--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%--引入springMVC form--%>
<%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <!-- Basic -->
    <meta charset="UTF-8"/>
    <title>编辑项目计划</title>
    <script type="application/javascript">
        //判断该表单是修改项目还是添加项目
        window.onload = function () {
            var planForm = document.getElementById("planForm");
            if ('${msg}' == '添加成功' || '${msg}' == '修改成功')
                window.location.href = "${pageContext.request.contextPath}/Plan/selPPAll.emp";
            if ('${plan.planId }' != 0) {
                planForm.action = "${pageContext.request.contextPath}/Plan/updatePlan.emp";
            }
        }
        //跳至查询页面
        function ToempShowPage() {
            window.location.href = "${pageContext.request.contextPath}/Plan/selPlanAll.emp";
        }
        //用ajax根据项目名查询项目
        function selByPName() {
            var pName = document.getElementById("projectName").value;
            var s = document.getElementById("suggest");
            s.innerHTML = "";
            var suggest = "";
            $.ajax({
                url: '${pageContext.request.contextPath}/Plan/selByPName.emp',
                data: {pName: pName},
                type: 'post',
                dataType: 'json',
                success: function (data) {
                    if (data.length>0) {
                        for (i = 0; i < data.length; i++) {
                            suggest += "<div onclick='sendPName("+i+")' id='"+i+"' style='margin:0;padding:0;width: 498px;background-color: white'>"+data[i].projectName+"</div><input id='pId"+i+"' type='hidden' value='"+data[i].projectId+"'/>";
                        }
                        s.innerHTML = suggest;
                        s.style.display = "block";
                    }else {
                        s.style.display = "none";
                    }
                }
            })
        }
        //为归属项目赋值，并记录该项目的id
        function sendPName(type) {
            //把项目名称放到input里
            document.getElementById("projectName").value = document.getElementById(type).innerHTML;
            //保存项目id到planProject里
            document.getElementById("planProject").value = document.getElementById("pId"+type).value;
            //清空div
            document.getElementById("suggest").innerHTML = "";
            document.getElementById("suggest").style.display = "none";
        }
        function go() {
            if ('${plan.planId }' != 0) {
                document.getElementById("planForm").action = "${pageContext.request.contextPath}/Plan/updatePlan.emp";
            }
        }
        function planList() {
            var planProject = document.getElementById("planProject").value;
            var planRank = document.getElementById("planRank").value;
            var planId = parseInt(document.getElementById("planId").value);
            var planSuper = document.getElementById("planSuper");
            $.ajax({
                url: '${pageContext.request.contextPath}/Plan/selByPlan.emp',
                data: {planProject: planProject,planRank:planRank},
                type: 'post',
                dataType: 'json',
                success: function (data) {
                    if (data.length>0) {
                        planSuper.innerHTML = "";
                        planSuper.options.add(new Option("请选择",0));
                        for (var i = 0; i < data.length; i++) {
                            if (planId!=parseInt(data[i].planId)) planSuper.options.add(new Option(data[i].planName,data[i].planId));
                        }
                    }else {
                        planSuper.innerHTML = "";
                        planSuper.options.add(new Option("请选择",0));
                    }
                }
            });
        }
        function planSuper() {
            var planProject = document.getElementById("planProject").value;
            var planRank = document.getElementById("planRank").value;
            if ((planProject==null||planProject.eq(""))&&(planRank==null||planRank.eq(""))){
                planSuper.innerHTML = "";
                planSuper.options.add(new Option("请选择",0));
            }
        }
    </script>
</head>
<body>.
<!--头部开始-->
<jsp:include page="headerBack.jsp"></jsp:include>
<!-- 导航 -->
<jsp:include page="leftBack.jsp"></jsp:include>
<!--内容页-->
<div class="main">
    <!--内容页头部-->
    <div class="page-header">
        <div class="pull-left">
            <ol class="breadcrumb visible-sm visible-md visible-lg">
                <li><a href="${pageContext.request.contextPath}/Login/goHomePage"><i class="icon fa fa-home"></i>主页</a></li>
                <li class="active"><i class="fa fa-pencil"></i>基本信息</li>
            </ol>
        </div>
        <div class="pull-right">
            <h2>主页</h2>
        </div>
    </div>
    <!-- End Page Header -->
    <div class="row profile">
        <div class="col-lg-11">
            <div class="col-lg-7 col-md-9 col-sm-12">
                <div class="panel">
                    <div class="panel-body">
                        <div class="tabs tabs-warning">
                            <ul class="nav nav-tabs">
                                <li class="active">
                                    <a href="#edit" data-toggle="tab">编辑信息</a>
                                </li>
                            </ul>
                            <div class="tab-content">
                                <div id="edit" class="tab-pane updateProfile active">
                                    <!--form表单-->
                                    <sf:form id="planForm" action="${pageContext.request.contextPath}/Plan/addPlan.emp"
                                             modelAttribute="plan" method="post">
                                        <div class="bk-bg-white bk-padding-top-10 bk-padding-bottom-10">
                                            <h4>编辑计划</h4>
                                            <fieldset>
                                                <div>
                                                    <span>${msg}</span>
                                                    <sf:input path="planId" type="hidden"/>
                                                </div>

                                                <div class="form-group">
                                                    <label>归属项目</label>
                                                    <sf:input type="hidden" path="planProject"/>
                                                    <input type="text" id="projectName" name="projectName" <c:if test="${plan.project!=null}">value="${plan.project.projectName}"</c:if><c:if test="${plan.projectName!=null}">value="${plan.projectName}"</c:if> oninput="selByPName()" autocomplete="off" style="margin-bottom: 0px" class="form-control"/>
                                                    <span id="suggest" style="width: 500px; position:absolute;display: none;margin:0;border: 1px solid #0066cc;padding:0"></span>
                                                    <span style="color: #ba0000"> ${errors.planProject} </span>
                                                </div>
                                                <div class="form-group">
                                                    <label>计划级别</label>
                                                    <input id="planRank" name="planRank" oninput="planList()" class="form-control" <c:if test="${plan.planRank != 0}">value="${plan.planRank}"</c:if> type="text" size="10" oninput="if (! /^\d+$/ig.test(this.value)){this.value='';}"/>
                                                    <span style="color: #ba0000"> ${errors.planRank} </span>
                                                </div>
                                                <div class="form-group">
                                                    <label>上级计划</label>
                                                    <sf:select path="planSuper" class="form-control" onclick="planSuper()">
                                                        <sf:option value="0">请选择</sf:option>
                                                        <c:if test="${planList==null}"><sf:options items="${planList}" id="planList" itemLabel="${planName}" itemValue="${planId}"/></c:if>
                                                    </sf:select>
                                                </div>
                                                <div class="form-group">
                                                    <label>计划名称</label>
                                                    <sf:input path="planName" type="text" class="form-control"/>
                                                    <span style="color: #ba0000"> ${errors.planName} </span>
                                                </div>
                                                <div class="form-group">
                                                    <label>开始时间</label>
                                                    <sf:input style="width: 95px" path="planStart" type="text" class="sang_Calender"/>
                                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                    <label>结束时间</label>
                                                    <sf:input style="width: 95px" path="planEnd" type="text" class="sang_Calender"/><br/>
                                                    <span style="color: #ba0000"> ${errors.planStart} </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                    <span style="color: #ba0000"> ${errors.planEnd} </span>
                                                </div>
                                                <div class="form-group">
                                                    <label>计划描述</label>
                                                    <sf:textarea rows="3" cols="67" path="planDescribe"></sf:textarea>
                                                    <span style="color: #ba0000"> ${errors.planDescribe} </span>
                                                </div>
                                            </fieldset>
                                            <div class="bk-bg-white">
                                                <div class="row">
                                                    <div class="col-md-12">
                                                        <div class="pull-right">

                                                            <button onclick="go()" type="submit" class="btn btn-primary">提交
                                                            </button>
                                                            &nbsp;&nbsp;
                                                            <button type="button" onclick="ToempShowPage()" class="btn btn-primary">取消
                                                            </button>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </sf:form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="${pageContext.request.contextPath}/dist/backEnd/js/datetime.js"></script>
</body>
</html>
